import xml.etree.ElementTree as ET

class ConstantesFrogger:
    CONFIG_FILENAME = 'Configuration.xml'
    DEFAULT_WIDTH = 600
    DEFAULT_HEIGHT = 650
    MIN_WIDTH = 500
    MIN_HEIGHT = 600
    MAX_WIDTH = 1600
    MAX_HEIGHT = 1200
    MINIJEU_POINTS = [100, 75, 50, 25]
    mourrir = 15
    ENTRER_ANSE = 15
    monterNiveau = 15
    
    couleurs = ["vert", "bleu", "rouge", "jaune"]
    
    def loadSizeConfig():
        arbre = ET.ElementTree()
        try:
            arbre.parse(ConstantesFrogger.CONFIG_FILENAME)
        except:
            ConstantesFrogger.saveSizeConfig(ConstantesFrogger.DEFAULT_WIDTH, ConstantesFrogger.DEFAULT_HEIGHT)
            return (ConstantesFrogger.DEFAULT_WIDTH, ConstantesFrogger.DEFAULT_HEIGHT)
        
        #width
        el = arbre.find('width')
        width = int(el.text);

        #height
        el = arbre.find('height')
        height = int(el.text);
        
        if(width>ConstantesFrogger.MAX_WIDTH):
            width = ConstantesFrogger.MAX_WIDTH
        elif(width<ConstantesFrogger.MIN_WIDTH):
            width = ConstantesFrogger.MIN_WIDTH
            
        if(height>ConstantesFrogger.MAX_HEIGHT):
            height = ConstantesFrogger.MAX_HEIGHT
        elif(height<ConstantesFrogger.MIN_HEIGHT):
            height = ConstantesFrogger.MIN_HEIGHT

        return (width, height)
    loadSizeConfig = staticmethod(loadSizeConfig)

    def saveSizeConfig(width, height):
        root = ET.Element('Configuration')
        
        #width
        widthEl = ET.SubElement(root, "width")  
        widthEl.text = str(width)

        #height
        heightEl = ET.SubElement(root, "height")  
        heightEl.text = str(height)
        
        arbre = ET.ElementTree(root)

        arbre.write(ConstantesFrogger.CONFIG_FILENAME)
    saveSizeConfig = staticmethod(saveSizeConfig)